﻿using Owin;
using Sustainalytics.Utils;
using System.Web.Http;
using System.Web.Http.Dispatcher;

namespace Sustainalytics.MostRecentActivity.Service
{
    public class Startup
    {
        public void Configuration(IAppBuilder builder)
        {
            builder.Use<OwinExceptionMiddleware>();

            builder.UseAuthenticationServer();

            var config = new HttpConfiguration();
            config.Filters.Add(new LogControllerFilter(true, true, false));

            var container = CompositionRoot.RegisterDependencies(config);

            config.Services.Replace(typeof(IHttpControllerActivator), new SimpleInjectorControllerActivator(container));

            WebApiConfig.Register(config);
            config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            builder.UseWebApi(config);

            config.EnsureInitialized();
        }
    }
}
